package com.visionet.school.app.web.web.tclass;

import com.visionet.school.app.web.common.utils.PageInfo;
import com.visionet.school.app.web.entity.tclass.vo.ClassActivityVo;
import com.visionet.school.app.web.service.tclass.ClassActivityService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by dzd on 2017/3/2.
 */
@RequestMapping("/activity")
@Controller
public class ClassActivityController {

    @Autowired
    private ClassActivityService classActivityService;

    @RequestMapping(value = "/wechat/findClassActivity", method = RequestMethod.GET)
    public ResponseEntity<?> findClassActivity(String id){
        Map<String,Object> map = new HashMap<>();
        if(id.isEmpty()){
            return new ResponseEntity(map , HttpStatus.NOT_ACCEPTABLE);
        }
        map.put("classActivity",classActivityService.findClassById(id));
        return new ResponseEntity(map , HttpStatus.OK);
    }

    @RequestMapping(value = "/wechat/getActivityPage", method = RequestMethod.POST)
    public ResponseEntity<?> getActivityPage(@RequestBody ClassActivityVo classActivityVo){
        if(classActivityVo == null || (StringUtils.isBlank(classActivityVo.getClassId()) && StringUtils.isBlank(classActivityVo.getClassId()))){
            return new ResponseEntity(null , HttpStatus.NOT_ACCEPTABLE);
        }
        if(classActivityVo.getPageInfo() == null){
            classActivityVo.setPageInfo(new PageInfo());
        }
        Map<String,Object> map = new HashMap<>();
        Map<String,Object> pageResult;
        try {
            pageResult = classActivityService.getActivityPage(classActivityVo,"activityTime");
            map.put("pageResult",pageResult);
        }catch (Exception e){
            e.printStackTrace();
            map.put("stat","err");
        }
        return new ResponseEntity(map , HttpStatus.OK);
    }

}
